shader10.c
#version 460
#pragma vp_entryPoint oe_rex_normalMapFS
#pragma vp_location   fragment_coloring
#pragma vp_order      0.1
#pragma import_defines(OE_TERRAIN_RENDER_NORMAL_MAP)
#pragma import_defines(OE_DEBUG_NORMALS)
#pragma import_defines(OE_DEBUG_CURVATURE)
#define VP_STAGE_FRAGMENT
// import terrain SDK
vec4 oe_terrain_getNormalAndCurvature(in vec2);
uniform sampler2D oe_tile_normalTex;
vec3 vp_Normal;
#pragma vp_varying_in vec3 vp_Normal
vec3 oe_UpVectorView;
#pragma vp_varying_in vec3 oe_UpVectorView
vec2 oe_normal_uv;
#pragma vp_varying_in vec2 oe_normal_uv
vec3 oe_normal_binormal;
#pragma vp_varying_in vec3 oe_normal_binormal
// global
mat3 oe_normalMapTBN;
void oe_rex_normalMapFS(inout vec4 color)
{
#ifndef OE_TERRAIN_RENDER_NORMAL_MAP
    return;
#endif
    vec4 N = oe_terrain_getNormalAndCurvature(oe_normal_uv);
    vec3 tangent = normalize(cross(oe_normal_binormal, oe_UpVectorView));
    oe_normalMapTBN = mat3(tangent, oe_normal_binormal, oe_UpVectorView);
    vp_Normal = normalize(oe_normalMapTBN*N.xyz);
#ifdef OE_DEBUG_CURVATURE
    // visualize curvature quantized:
    color.rgba = vec4(0, 0, 0, 1);
    float curvature = N.w;
    if (curvature > 0.0) color.r = curvature;
    if (curvature < 0.0) color.g = -curvature;
#endif
#ifdef OE_DEBUG_NORMALS
    // visualize normals:
    color.rgb = (N.xyz + 1.0)*0.5;
#endif
}
